-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add BIN for string function support #2219
Conversation
@siddontang , How could I rebase the two commit into one now. |
@a6802739 Thanks for your PR! |
@a6802739 You also need to add bin function syntax in parser package. I will send you a document to describe how to do this. |
@shenli, Thanks for you review. So would you mind send the document to my email |
if err != nil { | ||
return d, errors.Trace(err) | ||
} | ||
switch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to convert an integer to bytes, just use bit operator :)
for(v > 0){
if (v & 1 > 0){
bs = bs + '1'
} else {
bs = bs + '0'
}
v = v >> 1
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BE and LE is about encoding and decoding, needn't be considered here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var bs []string
for(v > 0){
if (v & 1 > 0){
bs = append(bs, "1")
} else {
bs = append(bs, "0")
}
v = v >> 1
}
i := 0
length := len(bs)
for i < length / 2 {
temp := bs[i]
bs[i] = bs[length-i-1]
bs[length-i-1] = temp
i = i + 1
}
rs := strings.Join(bs, "")
Or we could use a stack
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appending character '0' and '1' to a byte slice is more efficient than append strings to a string slice.
@a6802739
or
|
@a6802739 I seem like a negative integer will be converted to unsigned interger first. So the stdlib function we should use is |
@coocood,
So, it seems |
|
okay. got it. where should I use the function |
@a6802739 |
@a6802739 |
PTAL |
@a6802739 |
@coocood, where is |
@a6802739 Any update? |
@a6802739 |
I have add a function
BIN
for #310.cc @siddontang @coocood.
I wonder If I should take
negative number
into consider, I'm not sure ifmysql
supportnegative number
now?